import redis

try:
    r = redis.Redis(
        host="localhost",
        port=6379,
        password="123456",
        db=0
    )
    print(r.ping())  # 应输出 True
    r.set("test_key", "test_value")
    print(r.get("test_key"))  # 应输出 b'test_value'
except Exception as e:
    print(f"错误: {e}")
